<template>
  <div>
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>评价管理</el-breadcrumb-item>
        <el-breadcrumb-item>评价列表</el-breadcrumb-item>
      </el-breadcrumb>
      <el-card>
        <el-table :data="foodList" stripe border>
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-table :data="scope.row.remarks">
                <el-table-column type="index" label="序号"></el-table-column>
                <el-table-column label="评分" prop="comment">
                  <template slot-scope="remark">
                    <el-rate v-model="remark.row.comment" disabled text-color="#ff9900"></el-rate>
                  </template>
                </el-table-column>
                <el-table-column label="评价" prop="detail"></el-table-column>
                <el-table-column label="评价用户" prop="user.uname"></el-table-column>
                <el-table-column label="评价时间" prop="time"></el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column label="菜品名" prop="fname"></el-table-column>
          <el-table-column label="商家名" prop="restaurant.rnickname"></el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total" background>
        </el-pagination>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Remark',
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      foodList: []
    }
  },
  created () {
    this.getRemarkList()
  },
  methods: {
    // 当每页显示的最大数据条数发生变化时，调用该函数
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getMerchantList()
    },
    // 当当前页数发生变化时，调用该函数
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getMerchantList()
    },
    async getRemarkList () {
      const { data: res } = await this.$axios.get('/admin/food/query', { params: this.queryInfo })
      if (res.status !== 2000) {
        return this.$message.error('获取评价列表失败')
      }
      this.foodList = res.data.foods
      this.total = res.data.total
    }
  }
}
</script>

<style scoped>

</style>
